"""
author: yzh
date: 2021/1/19
"""
import requests
from apps.DjangoWeb.spider.previousQuery.getToken import tokenList, token

url = "https://webvpn.ecut.edu.cn/users/sign_in"

webvpncookieList = [""]
def webvpnCookie(username,password):
    token()
    r_vpn_login_data = {
        'utf8': '%E2%9C%93',  # ✓
        'authenticity_token': tokenList[0],
        'user[login]': username,
        'user[password]': password,
        'user[dymatice_code]': 'unknown',
        "user[otp_with_capcha]": "false",
        'commit': '登录 Login'
    }
    r_vpn_login_headers = {
        "Host": "webvpn.ecut.edu.cn",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3775.400 QQBrowser/10.6.4208.400",
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
        "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
        "Accept-Encoding": "gzip, deflate, br",
        "Cache-Control": "max - age = 0",
        "Connection": "keep-alive",
        "Referer": "https://webvpn.ecut.edu.cn/users/sign_in",
        "Cookie": tokenList[1],
        "Upgrade-Insecure-Requests": "1"
    }
    r_vpn = requests.post(url, data = r_vpn_login_data, headers = r_vpn_login_headers, allow_redirects = False)
    webvpncookieList[0] = r_vpn.headers['set-cookie']

    return webvpncookieList[0]